//
//  SetViewController.m
//  Moment
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 谭泽源. All rights reserved.
//

#import "SetViewController.h"
#import "TZYAboutViewController.h"
#import "TZYMineColletionViewController.h"


@interface SetViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *myTableView;
@property(nonatomic,retain)MBProgressHUD *hud;

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"设置";
    
    [self createTableView];
    
}


- (void)createTableView
{
    self.myTableView = [[UITableView alloc] init];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.showsVerticalScrollIndicator = NO;
    self.myTableView.backgroundColor = [UIColor whiteColor];
    
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    
    self.myTableView.rowHeight = GoodsCellHeight;
    
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    //[self.myTableView registerClass:[TZYGoodsCell class] forCellReuseIdentifier:@"TZYGoodsCell"];
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
//    TZYGoodsList *goodsModel = [self.goodsListArray objectAtIndex:indexPath.row];
//    
//    cell.goodListModel = goodsModel;
    
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"关于我们";
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"清除缓存";
    }else if (indexPath.row == 2){
        cell.textLabel.text = @"我的收藏";
    }

    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    if (indexPath.row == 0) {
        TZYAboutViewController *aboutVC = [[TZYAboutViewController alloc] init];
        [self.navigationController pushViewController:aboutVC animated:YES];
    } else if (indexPath.row == 1) {
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        float cacheSize = size / 1024.0 / 1024.0;
        NSString *string = [NSString stringWithFormat:@"缓存大小为%.2fMB", cacheSize];
        
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:string preferredStyle:UIAlertControllerStyleActionSheet];
        
        [self presentViewController:alertC animated:YES completion:^{
            
        }];
        
        // 创建提示框按钮
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"清除缓存" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            // 清除缓存
            [[SDImageCache sharedImageCache] clearDisk];
            // hud单例
            self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            self.hud.labelText = @"清除缓存成功";
            self.hud.mode = MBProgressHUDModeText;
            [self.hud hide:YES afterDelay:1];
            
        }];
        // 创建提示框按钮
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            
        }];
        // 将按钮放在提示框上
        [alertC addAction:action];
        [alertC addAction:action1];
        
        

    } else if (indexPath.row == 2) {
        TZYMineColletionViewController *mineVC = [[TZYMineColletionViewController alloc] init];
        [self.navigationController pushViewController:mineVC animated:YES];
    }
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
